<%@ tag language="java" pageEncoding="UTF-8" %>  
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
<%@ attribute name="recordId" required="true" rtexprvalue="true"%>
<%@ attribute name="moduleCode" required="true" rtexprvalue="true"%>

<div id="opLogPanel"  ng-controller="OpLogCtrl">   
 <p><button type="button" class="btn" ng-click="reloadLogs();"><i class="icon-refresh"></i> <s:message code="btn.refresh"/></button></p>                            
  
  <div class="media" style="border-bottom: 1px dashed #EAEAEA;" ng-repeat="row in opLogs" id="opLogRow{{$index}}">
    <a class="pull-left" href="#">
      <img class="user-photo" src="${contextPath }/upload/avatar/avatar.gif"  ng-if="!row.opUserAvatar">
      <img class="user-photo" src="${contextPath }/upload/avatar/{{row.opUserAvatar}}_2.jpg"  ng-if="row.opUserAvatar">
    </a>
    <div class="media-body">
      <p class="media-heading">{{row.opUsername}}:{{row.action}}:{{row.opContent}}</p>
      <p>{{row.opDatetime | date:"yyyy-MM-dd HH:mm:ss"}}&nbsp;&nbsp;&nbsp;&nbsp;</p>
    </div>
  </div>  
    
</div>

<script type="text/javascript">
$(document).ready(function(){ 
  
  angular.element(document).ready(function() {  
    angular.bootstrap(document, [
            function ($httpProvider) {
              
              // Use x-www-form-urlencoded Content-Type
                $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
               
                /**
                 * The workhorse; converts an object to x-www-form-urlencoded serialization.
                 * @param {Object} obj
                 * @return {String}
                 */ 
                var param = function(obj) {
                  var query = '', name, value, fullSubName, subName, subValue, innerObj, i;
                    
                  for(name in obj) {
                    value = obj[name];
                      
                    if(value instanceof Array) {
                      for(i=0; i<value.length; ++i) {
                        subValue = value[i];
                        fullSubName = name + '[' + i + ']';
                        innerObj = {};
                        innerObj[fullSubName] = subValue;
                        query += param(innerObj) + '&';
                      }
                    }
                    else if(value instanceof Object) {
                      for(subName in value) {
                        subValue = value[subName];
                        fullSubName = name + '[' + subName + ']';
                        innerObj = {};
                        innerObj[fullSubName] = subValue;
                        query += param(innerObj) + '&';
                      }
                    }
                    else if(value !== undefined && value !== null)
                      query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
                  }
                    
                  return query.length ? query.substr(0, query.length - 1) : query;
                };
               
                // Override $http service's default transformRequest
                $httpProvider.defaults.transformRequest = [function(data) {
                  return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
                }];
              } 
        ]);  
      });
}); 

function OpLogCtrl($scope, $http) {
  $scope.opLogs = [];
  $scope.formData = {};
  //init
  $http.get('${contextPath}/system/userOpLog/getLogs.json?moduleCode=${moduleCode}&recordId=${recordId}', {
  }).success(function(data) {
      $scope.opLogs = data.userOpLogs;      
  }); 
  
  $scope.reloadLogs = function(){
    $http.get('${contextPath}/system/userOpLog/getLogs.json?moduleCode=${moduleCode}&recordId=${recordId}', {
    }).success(function(data) {
        $scope.opLogs = data.userOpLogs;      
    }); 
  }
}
</script> 